package com.wolf.serialization;

import com.wolf.enums.SerialEnum;

import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @auth: dylan
 * @Desc: 序列化器工厂
 * @Time: 2024/4/30
 */
public class SerialFactory {
    private volatile static ConcurrentHashMap<Byte, Serializer> CONTAINER;

    public SerialFactory() {
        if (CONTAINER == null) {
            synchronized (SerialFactory.class) {
                if (CONTAINER == null) {
                    CONTAINER = new ConcurrentHashMap<>(SerialEnum.values().length);
                    CONTAINER.put(SerialEnum.JSON.getType(), new JsonSerializer());
                }
            }
        }
    }

    public static Serializer get(Byte serialType) {
        return CONTAINER.get(serialType);
    }
}
